<?php


namespace app\admin\controller;


use app\common\model\FootballGuessBetModel;
use app\common\model\FootballGuessModel;
use app\common\model\FootballMatchModel;
use think\facade\Request;

class GuessController extends BaseController
{
    public function index(){
        return $this->fetch();
    }

    public function bet(){
        return $this->fetch();
    }

    public function index_match(){
        $match = FootballMatchModel::where(['id'=>Request::param('id')])->find();
        $this->assign("match",$match);
        return $this->fetch();
    }

    public function add(){
        $this->assign("matchid",Request::param('matchid'));
        return $this->fetch();
    }

    public function getlist(){
        $page = Request::param("page");
        $limit = Request::param("limit");
        $list = FootballGuessModel::limit(($page-1)*$limit,$limit)->select();
        if (!count($list)){
            return self::bulidFail("未查询到相关数据");
        }
        $count = FootballGuessModel::count("id");
        return json(["code"=>0,"msg"=>"","data"=>$list,"count"=>$count]);
    }

    public function getBetList(){
        $page = Request::param("page");
        $limit = Request::param("limit");
        $list = FootballGuessBetModel::limit(($page-1)*$limit,$limit)->select();
        if (!count($list)){
            return self::bulidFail("未查询到相关数据");
        }
        $count = FootballGuessBetModel::count("id");
        return json(["code"=>0,"msg"=>"","data"=>$list,"count"=>$count]);
    }

    public function getlistbymatch(){
        $list = FootballGuessModel::where(['matchid'=>Request::param('matchid')])->select();
        if (!count($list)){
            return self::bulidFail("未查询到相关数据");
        }
        return self::bulidSuccess($list);
    }

    public function add_post(){
        $guess = new FootballGuessModel(Request::param());
        $guess->create_time = nowFormat();
        if ($guess->save()){
            return self::bulidSuccess();
        }
        return self::bulidFail();
    }
}